import React, {useState, useEffect} from 'react'
import Dashboard from '../Dashboard'
import { getCodeByKey } from '../../utils/utils';
import services from '../../services/api';
import { message } from 'antd';
import './index.less'
function report(props) {
  const [paramsData, setParams] = useState({});
  const [echoParams, setEchoParams] = useState()
  useEffect(() => {
    getParams();
  },[props.location.search]);
  // 获取连接参数
  function getParams() {
    const report_id = getCodeByKey(props.location.search, 'report_id');
    const send_time = getCodeByKey(props.location.search, 'send_time');
    const token = getCodeByKey(props.location.search, 'token');
    const params = {
      report_id: report_id,
      send_time: send_time,
      token: token,
    };
    getQueryParams(params);
  };
  // 获取时间
  function getQueryParams(data) {
    services.report.getQueryParams(data).then((res) => {
      if (res.code === 0) {
        const {start, end, app_id, event_id, report_id, product_id} = res.data
        data.start = start;
        data.end = end;
        data.app_id = app_id;
        data.event_id = event_id;
        data.report_id = report_id;
        data.product_id = product_id;
        setEchoParams(res.data);
        setParams(data);
      } else {
        message.error(res.msg);
      }
    });
  };
  return (
    <div className='report-boxs'>
     <Dashboard hideDetail={true} isDisable={true} actionType={'report'} echoParams={echoParams} seachParams={paramsData} ></Dashboard>
     </div>
  )
};
export default report;